
var sizeWrap=function(){
    var minHeight=document.querySelector('.loginContents').clientHeight;
    var head=document.querySelector('.loginHead').clientHeight;
    var column=document.querySelector('.autoHeight').offsetHeight;
    console.log(minHeight);
    console.log('head'+head+'-'+column);
    document.querySelector(".autoHeight").style.marginTop=(minHeight-column)/2+'px';
};
window.onload=function(){
    sizeWrap()
};
window.onresize=function(){
    sizeWrap()
};

$(function(){
    //登录注册切换
    $(".loginSignBut button").click(function(){
        var index=$(this).index();
        $(".loginSignBut button").eq(index).addClass('on').siblings("button").removeClass("on");
        $(".signTab").eq(index).trigger("click");
    });
    $(".signTab").click(function(){
        var index=$(this).index();
        $(this).addClass('on').siblings('.signTab').removeClass('on');
        $(".signTogWrap").eq(index).addClass('on').siblings('.signTogWrap').removeClass('on');
        $(".loginSignBut button").eq(index).addClass('on').siblings("button").removeClass("on");
        if(index==1){
            $(".signWrap").addClass('on');
        }else{
            $(".signWrap").removeClass('on');
        }
    });

    //登录
    $(".signSubmitBut").click(function(){
        var phone=$("input[name='phone']").val();
        var password=$("input[name='password']").val();
        var reg = new RegExp(/^1\d{10}$/);
        if(phone==''){
            layTxt('手机号不能为空')
        }else if(password==''){
            layTxt('密码不能为空')
        }else{
            //登录
            var arr1={
                name:phone,
                password:password
            };
            $.ajax({
                type: "POST",
                url:base_url + "login",
                data:arr1,
                beforeSend:function(XMLHttpRequest){},
                success:function(data){
                    console.log(data);
                    var datas=data;
                    if(datas.is_success){
                        if(datas.auth_token){
                            setCookie('auth_token',datas.auth_token);//设置cookie
                            layTxt('登录成功');

                            qctpToTp();//默认历史真题tp
                            setTimeout(function(){
                                setUrl('login','overyears')//设置跳转
                            },1000);
                        }
                    }else{
                        layTxt('登录失败')
                    }
                },
                error:function(){
                    console.log('失败')
                }

            });
        }
    });

    //注册
    $(".signRegisterBut").click(function(){
        var registerPhone=$("input[name='registerPhone']").val();
        var registerPassword=$("input[name='registerPassword']").val();
        var registerPasswordAgain=$("input[name='registerPasswordAgain']").val();
        var reg = new RegExp(/^1\d{10}$/);
        if(registerPhone==''){
            layTxt('手机号不能为空')
        }else if(!reg.test(registerPhone)){
            layTxt('手机号格式不正确')
        }else if(registerPassword==''||registerPasswordAgain==''){
            layTxt('密码不能为空')
        }else if(registerPassword!==registerPasswordAgain){
            layTxt('密码不一致')
        }else{
            var arr1={
                name:registerPhone,
                password:registerPassword
            };
            $.ajax({
                type: "POST",
                url:base_url + "register",
                data:arr1,
                beforeSend:function(XMLHttpRequest){},
                success:function(data){
                    console.log(data);
                    var datas=data;
                    if(datas.is_success){
                        layTxt('注册成功');
                        $(".signTab").eq(0).trigger('click');
                        $("input[name='phone']").val(registerPhone)
                    }else{
                        layTxt('注册失败,换个手机号试试')
                    }
                },
                error:function(){
                    console.log('失败')
                }

            });
        }
    })
});